<%@ page language="java" pageEncoding="UTF-8"%>

<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles"%>
<%
	String path = request.getContextPath();
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html lang="true">
<head>
	<html:base />

	<title>listUser.jsp</title>
	<link href="./css/xtab.css" rel="stylesheet" type="text/css" />


</head>

<body>
	<html:form action="/user.do">
		<html:hidden property="method" value="user.do?method=search" />

		<table cellspacing="0" width="100%" border="1" onkeydown="keyDown(event);">

			<tr>
				<td class="tableTitle">
					用户名
				</td>
				<td>
					<html:text property="user.userName"></html:text>
				</td>
				<td class="tableTitle">
					邮箱地址
				</td>
				<td>
					<html:text property="user.email"></html:text>
				</td>
			</tr>
			
			
			<tr>
				<td colspan="4" align="center">
					<input type="button" class="button" id="search" value="搜 索">
					<input type="button" class="button" id="clear" value="清 空">
				</td>
			</tr>
		</table>
		<table align="center" width="100%" cellspacing="0">
			<tr>
				<th class="tableTitle">
					用户头像
				</th>
				<th class="tableTitle">
					用户名
				</th>
                <th class="tableTitle">
					邮箱地址
				</th>
				
				<th class="tableTitle">
					个性签名
				</th>
				<th class="tableTitle">
					操作
				</th>

			</tr>
			<logic:iterate id="s" name="pageBean" property="list">
				<tr>
					<td class="tableElement">
						 <logic:notEmpty property="userImg" name="s">
							<img src="<%=path%>/servlet/ShowImgServlet?fileName=${s.userImg }" width="20" height="20" onclick="popickerWin('<%=path%>/servlet/ShowImgServlet?fileName=${s.userImg }')">
					     </logic:notEmpty>
					</td>
					<td class="tableElement">
						${s.userName }
					</td>
					<td class="tableElement">
						${s.email }
					</td>
					<td class="tableElement">
						${s.userSignature } 
					</td>
					
					<td class="tableElement">
						<img src="<%=path%>/images/update.gif"
							onclick="updt('${s.userId }')">
						<img src="<%=path%>/images/delete.gif"
							onclick="del('${s.userId }')">
					    <input type="button" class="button" value="授权" onclick="userGrant('${s.userId }');">		
					</td>
				</tr>
			</logic:iterate>
		</table>
		<jsp:include page="../common/pagtion.jsp"></jsp:include>
		<br>
		<div align="center">
			<input type="button" id="toCreateUser" class="button" value="添加">
		</div>

		<script>
	$("#toCreateUser").click(function(){
		var f=document.forms[0];
		f.action="user.do?method=toCreateUser";
		f.submit();
	}); 
	updt=function(val){
	    var f=document.forms[0];
		f.action="user.do?method=toUpdateUser&id="+val;
		f.submit();
	}
	$("#search").click(function(){
		var f=document.forms[0];
		f.action="user.do?method=search";
		f.submit();
	}); 
	
	$("#clear").click(function(){
		var f=document.forms[0];
		f.action="user.do?method=init";
		f.submit();
	});
	
	del=function(val){
	    if(confirm("确定要删除吗?")){
		    var f=document.forms[0];
			f.action="user.do?method=delUser&id="+val;
			f.submit();
		}
	} 
	
	function keyDown(event){
	    if(event.keyCode==13)
	    {
			$("#search").click();
			//event.returnValue=false; 
		}
	}
	
	function userGrant(userId){
		 var f=document.forms[0];
		 f.action="user.do?method=toUserGrant&id="+userId;
		 f.submit();
	}
	
	function popickerWin(src)
	{
		 var content2 = "<img width='640' height='466' src='"+src+"' />";
       	 TINY.box.show(content2,0,0,0,1)
		 
	}
	</script>
	</html:form>
</body>
</html:html>
